﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Hrm.Core;

namespace Hrm.EntityFramework
{
    public class HrmDbContext : BaseDbContext
    {
        #region Properties


        public DbSet<Department> Departments { get; set; }

        public DbSet<Company> Companys { get; set; }

        public DbSet<Staff> Staffs { get; set; }
        public DbSet<ClassMate> ClassMates { get; set; }
        public DbSet<ClassMateExtention> ClassMateExtentions { get; set; }
        public DbSet<School> Schools { get; set; }

        #endregion

        #region Ctor

        public HrmDbContext()
            : base("name=HrmDbConnectionStrings")
        {
            //((IObjectContextAdapter)this).ObjectContext.ContextOptions.LazyLoadingEnabled = true;
        }

        public HrmDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
        }

        #endregion

        #region Utilities

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //var assemblys = _typeFinder.GetAssemblies().ToArray();
            //foreach (var assembly in assemblys)
            //{
            //    var typesToRegister = assembly.GetTypes()
            //        .Where(type => !String.IsNullOrEmpty(type.Namespace))
            //        .Where(
            //            type =>
            //                type.BaseType != null &&
            //                type.BaseType == typeof(Entity));// type.BaseType.IsGenericType &&type.BaseType.GetGenericTypeDefinition() == typeof(Entity));
            //    foreach (var type in typesToRegister)
            //    {
            //        dynamic configurationInstance = Activator.CreateInstance(type);
            //        modelBuilder.Configurations.Add(configurationInstance);
            //    }
            //}
            base.OnModelCreating(modelBuilder);
        }

        #endregion


    }
}
